import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:my_app/pages/widget_demos/button_test.dart';
import 'package:my_app/pages/widget_demos/navigation_bar.dart';
import 'package:my_app/pages/widget_demos/navigation_bar_individual.dart';
import 'package:my_app/pages/widget_demos/nested.dart';
import 'package:my_app/pages/widget_demos/form_test.dart';
import 'package:my_app/pages/widget_demos/layout_test.dart';
import 'package:my_app/pages/widget_demos/list_test.dart';
import 'package:my_app/pages/widget_demos/maxheight_and_scroll.dart';
import 'package:my_app/pages/widget_demos/mixed_scroll.dart';
import 'package:my_app/pages/widget_demos/shopping_list.dart';
import 'package:my_app/pages/widget_demos/card_and_input.dart';
import 'package:my_app/pages/widget_demos/temp.dart';

/// 使用dart3.x的增强枚举来集中管理路由地址与页面
/// 
/// 便于使用Ctrl+鼠标左键查看对应页面
/// 
/// 如果有需要，也可增加name选项
enum WidgetRouters {
  tempPage('/temp-page', TempPage()),
  btnTest('/btn-test', ButtonTestPage()),
  formTest('/form-test', FormTestPage()),
  shoppingList('/shopping-list', ShoppingListPage()),
  listTest('/list-test', ListTestPage()),
  cardAndInput('/card-and-input', CardAndInputPage()),
  maxheightAndScroll('/maxheight-and-scroll', MaxHeightAndScrollPage()),
  layoutTest('/layout-test', LayoutTestPage()),
  mixedScroll('/mixed-scroll', MixedScrollPage()),
  nestedScroll('/nested-scroll', NestedScrollPage()),
  navigationBar('/navigation-bar', NavigationBarPage()),
  navigationBarIndividual('/navigation-bar-individual', NavigationBarIndividualPage()),
  ;

  const WidgetRouters(this.path, this.page);

  final String path;
  final Widget page;
}

List<RouteBase> generateWidgetRoutes(GlobalKey<NavigatorState> rootkey) {
  return WidgetRouters.values.map<RouteBase>((e) {
    return GoRoute(
      path: e.path,
      parentNavigatorKey: rootkey,
      builder: (context, state) => e.page,
    );
  }).toList();
  // return <RouteBase> [
  //   GoRoute(
  //     path: WidgetRouters.tempPage.path,
  //     parentNavigatorKey: rootkey,
  //     builder: (context, state) => WidgetRouters.tempPage.page,
  //   ),
  //   GoRoute(
  //     path: WidgetRouters.btnTest.path,
  //     parentNavigatorKey: rootkey,
  //     builder: (context, state) => WidgetRouters.btnTest.page,
  //   ),
  //   GoRoute(
  //     path: WidgetRouters.formTest.path,
  //     parentNavigatorKey: rootkey,
  //     builder: (context, state) => WidgetRouters.formTest.page,
  //   ),
  //   GoRoute(
  //     path: WidgetRouters.shoppingList.path,
  //     parentNavigatorKey: rootkey,
  //     builder: (context, state) => WidgetRouters.shoppingList.page,
  //   ),
  //   GoRoute(
  //     path: WidgetRouters.listTest.path,
  //     parentNavigatorKey: rootkey,
  //     builder: (context, state) => WidgetRouters.listTest.page,
  //   ),
  //   GoRoute(
  //     path: WidgetRouters.cardAndInput.path,
  //     parentNavigatorKey: rootkey,
  //     builder: (context, state) => WidgetRouters.cardAndInput.page,
  //   ),
  //   GoRoute(
  //     path: WidgetRouters.maxheightAndScroll.path,
  //     parentNavigatorKey: rootkey,
  //     builder: (context, state) => WidgetRouters.maxheightAndScroll.page,
  //   ),
  //   GoRoute(
  //     path: WidgetRouters.layoutTest.path,
  //     parentNavigatorKey: rootkey,
  //     builder: (context, state) => WidgetRouters.layoutTest.page,
  //     // 路由的errorBuilder并不能捕获下面throw的Exception
  //     // builder: (context, state) {
  //     //   int i = Random().nextInt(5);
  //     //   print(i);
  //     //   if (i < 3) {
  //     //     throw UnauthorizedException("鉴权错误");
  //     //   }
  //     //   return WidgetRouters.layoutTest.page;
  //     // },
  //   ),
  //   GoRoute(
  //     path: WidgetRouters.mixedScroll.path,
  //     parentNavigatorKey: rootkey,
  //     builder: (context, state) => WidgetRouters.mixedScroll.page,
  //   ),
  //   GoRoute(
  //     path: WidgetRouters.nestedScroll.path,
  //     parentNavigatorKey: rootkey,
  //     builder: (context, state) => WidgetRouters.nestedScroll.page,
  //   ),
  //   GoRoute(
  //     path: WidgetRouters.navigationBar.path,
  //     parentNavigatorKey: rootkey,
  //     builder: (context, state) => WidgetRouters.navigationBar.page,
  //   ),
  //   GoRoute(
  //     path: WidgetRouters.navigationBarIndividual.path,
  //     parentNavigatorKey: rootkey,
  //     builder: (context, state) => WidgetRouters.navigationBarIndividual.page,
  //   ),
  // ];
}

// class UnauthorizedException extends GoException {
//   UnauthorizedException(super.message);
// }